home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: strncpy() ?
- Date: 21 Apr 1996 16:44:09 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4ldokp$cgl@sparcserver.lrz-muenchen.de>
- References: <4ldkvd$553@venus.compulink.gr>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- lonewolf@athena.compulink.gr (Costas Vlassis) writes:
-
-
- > Well I have this question, let's say we have the following :
-
- >char alfa[40] = "1123";
- >char beta[20];
- >char gama[20];
-
- >With strncpy(beta,alfa,2) beta = "11" that's fine but HOW can I make
- >gama = "23" that is the last 2 characters of alfa or even "3" the last
- >character... Is there a function that takes start and end as strings ?
-
- >what I want is something like :
-
- >strncpy2 (beta,alfa,2,4);
-
- > is this possible ?
-
- Yes, but not under that name for name conflict reasons (the name is not
- free for your use).
-
- #include <string.h>
-
- char *
- str_ncpy2(char *dest, const char *src, size_t from, size_t to)
- {
- return strncpy(dest, src + from, to - from);
- }
-
- You might want to add error checking to prevent strange results
- when "to" is less than "from", or if "src" is not at least "from"
- characters long.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-
-